<template>
  <div class="mod-sp__spbasematchitem">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.itemName" placeholder="赛项名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <ren-select v-model="dataForm.itemClassify" dict-type="itemClassify" placeholder="赛项类别 取字典"></ren-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('sp:spbasematchitem:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('sp:spbasematchitem:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="sort" label="序号" header-align="center" align="center">
        <template v-slot="scope">
          <!--不足3位前面补0-->
          {{ getSort(scope.row.sort) }}
        </template>
      </el-table-column>
      <el-table-column prop="itemName" label="赛项名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="itemClassify" label="赛项类别" header-align="center" align="center">
        <template v-slot="scope">
          {{ getDictLabel2("itemClassify", scope.row.itemClassify) }}
        </template>
      </el-table-column>
      <el-table-column prop="itemType" label="赛项分类" header-align="center" align="center">
        <template v-slot="scope">
          {{ getDictLabel2("itemType", scope.row.itemType) }}
        </template>
      </el-table-column>
      <el-table-column prop="teacherNum" label="老师数量" header-align="center" align="center"></el-table-column>
      <el-table-column prop="teacherNumMax" label="老师数量" header-align="center" align="center"></el-table-column>
      <el-table-column prop="studentNum" label="学生数量" header-align="center" align="center"></el-table-column>
      <el-table-column prop="studentNumMax" label="学生数量" header-align="center" align="center"></el-table-column>
      <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="hasPermission('sp:spbasematchitem:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('sp:spbasematchitem:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./spbasematchitem-add-or-update.vue";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/sp/spbasematchitem/page",
      getDataListIsPage: true,
      exportURL: "/sp/spbasematchitem/export",
      deleteURL: "/sp/spbasematchitem",
      deleteIsBatch: true,
      dataForm: {
        itemName: "",
        itemClassify: ""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {},
  methods: {
    // 不足3位，前面补0
    getSort(val: number) {
      return val.toString().padStart(3, "0");
    }
  }
});
</script>
